// 引入api 
import { reqCategoryList, reqGetBannerList, reqGetFloorList } from "@/api/index";
// home数据模块
const state = {
  // 初始化时的数据
  categoryList: [],
  // 轮播图的空数组
  bannerList: [],
  // 根据服务器返回的内容确定是留空数组、空对象、
  // floor轮播图空数组
  floorList: []
};
const mutations = {
  // 往仓库写数据
  CATEGORYLIST (state, categoryList) {
    state.categoryList = categoryList
  },
  GETBANNERLIST (state, bannerList) {
    state.bannerList = bannerList;
  },
  GETFLOORLIST (state, floorList) {
    state.floorList = floorList
  }

};
const actions = {
  // 通过api的接口向服务器发送请求,并接收返回的数据
  async categoryList ({ commit }) {
    let result = await reqCategoryList();
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data)
    }
    // console.log(result)
  },
  // 获取首页轮播图数据
  async getBannerList ({ commit }) {
    // 从mock获取数据
    let result = await reqGetBannerList();
    if (result.code == 200) {
      commit('GETBANNERLIST', result.data)
    }
  },
  // floor轮播图
  async getFloorList ({ commit }) {
    //从mock取数据
    let result = await reqGetFloorList();
    if (result.code == 200) {
      commit('GETFLOORLIST', result.data)
    }
  }
};
const getters = {};

export default {
  state,
  mutations,
  actions,
  getters
}

